package router

import (
	"gitee.com/game_diamond/consts"
	"gitee.com/game_diamond/server"
	"gitee.com/game_diamond/session"
)

func init() {
	server.RegisterWsOnConnect(consts.ActorStudent, OnStudentConnect)
}

//学生断线重连
func OnStudentConnect(studentId int) {
	ss := session.GetGlobalStudentSession(studentId)
	ss.OnlineStatus = 1
	ss.Save()

	if ss.RoomId != "" {
		//存在房间
		switch ss.CourseType {
		case consts.CourseTypeAI:
			RouterAiStudentConnect(studentId)
		default: //回大厅
			RouterCenterStudentConnect(studentId)
		}
	} else {
		RouterCenterStudentConnect(studentId)
	}
}

func OnStudentClose() {
	studentId := 0
	ss := session.GetGlobalStudentSession(studentId)
	ss.OnlineStatus = 0
	ss.Save()

	if ss.RoomId != "" {
		//存在房间
		switch ss.CourseType {
		case consts.CourseTypeAI:
			RouterAiStudentClose(studentId)
		default: //回大厅
			RouterCenterStudentClose(studentId)
		}
	} else {
		RouterCenterStudentClose(studentId)
	}

}

//老师断线重连
func OnTeacherConnect() {

}

func OnTeacherClose() {

}
